﻿IF object_id(N'dbo.TabMailGrpMemb', 'U') IS NULL
BEGIN
    CREATE TABLE [dbo].[TabMailGrpMemb] (
        [MailGroupID] numeric(18,0) NOT NULL,
        [UserID]      numeric(18,0) NOT NULL,

        CONSTRAINT [PK_TabMailGrpMemb] PRIMARY KEY CLUSTERED ([MailGroupID] asc, [UserID] asc),
        CONSTRAINT [FK_TabMailGroupMember_TabAccountIndex] FOREIGN KEY ([UserID]) REFERENCES [dbo].[TabAccountIndex] ([UserID]),
        CONSTRAINT [FK_TabMailGroupMember_TabMailGroup] FOREIGN KEY ([MailGroupID]) REFERENCES [dbo].[TabMailGroup] ([MailGroupID]) ON DELETE CASCADE ON UPDATE CASCADE
    );
END
GO
